package com.jiang.专题.队列.Q232;

import java.util.Stack;

/**
 * @author Jiang
 * @version 1.0
 * @date 2025/03/02 19:03
 */
class MyQueue {
    Stack<Integer> s1;
    Stack<Integer> s2;

    public MyQueue() {
        s1 = new Stack<>();
        s2 = new Stack<>();
    }

    public void push(int x) {
        s1.push(x);
    }

    public int pop() {
        if (s2.isEmpty()) {
            s1ToS2();
        }
        return s2.pop();
    }

    public int peek() {
        if (s2.isEmpty()) {
            s1ToS2();
        }
        return s2.peek();
    }

    public boolean empty() {
        return s1.isEmpty() && s2.isEmpty();
    }

    private void s1ToS2() {
        while(!s1.isEmpty()) {
            s2.push(s1.pop());
        }
    }
}

